#########################################################################
# Time-stamp: <2004-02-25 23:04:32 patrick>
#
# Clustering Comparison dynamic data routines
#########################################################################
package EP::EPC::Interface::Clustering_Comparison;

use strict;

use EP::EPC::Interface;
use EP::Config;

sub newDD {
  my $proto = shift;
  my $ep_query_doc = shift;
  my $query = shift;
  my $DDD = shift;

  my $class = ref($proto) || $proto;
  my $self  = {};
  bless $self, $class;
  $self->initialize($ep_query_doc, $query, $DDD);
  return $self;
} #newDD

sub initialize {
  my $self = shift;
  $self->{epc_query} = shift;
  $self->{query}     = shift;
  $self->{DDD}       = shift;

  return;
} #initialize


#***************************************************************
#lists available clusterings for each dataset, uses &get_clustfiles_for_dataset
#***************************************************************
sub list_clustersets {
  my $self = shift;
  my $folder = shift;
  my $username = $self->{DDD}->get_username();
  my $session;

  if ( EP::Common::DB::session_data_only ( $self->{DDD}->get_username() ) == 1 ) {
    $session = $self->{DDD}->get_session_id();
  }

  my $data = { folder   => $folder,
               username => $username,
	       session  => $session
             };

  my $dataset = EP::Common::DB::get_dataset ( $data );

  my $scheme;     #hash ref!!
  my $count = 0;

  for ( my $i = 0; $i < keys ( %$dataset ); $i++ ) { #loop through datasets
    my $dataset_clusterings = EP::Common::DB::get_dataset_clusterings ( $dataset->{$i}{key} );

    foreach my $clustering ( @$dataset_clusterings ) {
      my $action_metadata = eval "my " . $clustering->[0];

      $scheme->{$count}{key}          = $action_metadata->{clustering};
      $scheme->{$count}{value}        = $dataset->{$i}{value};
      $scheme->{$count}{Clusters}     = $action_metadata->{K};
      ( $scheme->{$count}{Linkage} )  = $action_metadata->{clustering} =~ /\.K=.*?\..*?\.(.*?)\./;
      ( $scheme->{$count}{Method} )   = $action_metadata->{clustering} =~ /\.K=.*?\.(.*?)\./;
      ( $scheme->{$count}{Distance} ) = $action_metadata->{distance} =~ /\.(.*?)\.dist/;

      $count++;
    }
  }

  my $dl = &EP::EPC::Interface::DD::dynamic_list ( $scheme );
  return $dl->findnodes ( '/*' );
} #list_clustersets

1;
